package com.llm.travel_agent_assistant.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.llm.travel_agent_assistant.dto.Result;
import com.llm.travel_agent_assistant.entity.BudgetAnalyze;
import com.llm.travel_agent_assistant.mapper.BudgetAnalyzeMapper;
import com.llm.travel_agent_assistant.service.BudgetAnalyzeService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BudgetAnalyzeServiceImpl implements BudgetAnalyzeService {

    @Resource
    private BudgetAnalyzeMapper budgetAnalyzeMapper;

    @Override
    public Result getAnalysisByUserId(String userId) {
        QueryWrapper<BudgetAnalyze> wrapper = new QueryWrapper<>();
        wrapper.eq("owner_id", userId)
               .orderByDesc("create_time");
        List<BudgetAnalyze> list = budgetAnalyzeMapper.selectList(wrapper);
        return Result.ok(list);
    }

    @Override
    public Result getAnalysisById(String analyzeId) {
        QueryWrapper<BudgetAnalyze> wrapper = new QueryWrapper<>();
        wrapper.eq("analyze_id", analyzeId);
        BudgetAnalyze analysis = budgetAnalyzeMapper.selectOne(wrapper);
        if (analysis == null) {
            return Result.fail("未找到对应的费用预算分析");
        }
        return Result.ok(analysis);
    }

    @Override
    public Result deleteAnalysisById(String analyzeId) {
        QueryWrapper<BudgetAnalyze> wrapper = new QueryWrapper<>();
        wrapper.eq("analyze_id", analyzeId);
        int deleted = budgetAnalyzeMapper.delete(wrapper);
        if (deleted > 0) {
            return Result.ok("删除成功");
        } else {
            return Result.fail("删除失败，未找到对应的费用预算分析");
        }
    }
}
